#ifndef DEVICEVIEW_H
#define DEVICEVIEW_H

#include "rightwidget.h"

class DeviceTypeWidget : public QWidget
{
    Q_OBJECT
public:
    DeviceTypeWidget(QWidget *parent = 0);
    virtual ~DeviceTypeWidget();

public:
    void init();

protected:
    void updateListType();
    void updateListPoint();

signals:
    void sigModified();

protected slots:
    void addType();
    void removeType();
    void beginRenameType(QListWidgetItem* item);
    void renameType(QWidget* editor);
    void typeSelectionChanged(int);

    void addPoint();
    void removePoint();
    void beginRenamePoint(QListWidgetItem* item);
    void renamePoint(QWidget* editor);
    void filterSelectionChanged(int);

private:
    QListWidget* m_lwDeviceType;
    QPushButton* m_pbDtAdd;
    QPushButton* m_pbDtRemove;

    QListWidget* m_lwPoint;
    QComboBox* m_cbpFilter;
//    QComboBox* m_cbPointType;
    QPushButton* m_pbpAdd;
    QPushButton* m_pbpRemove;

    QString m_curTypeName;
    quint32 m_curPoint;
};

class DeviceWidget : public QWidget
{
    Q_OBJECT
public:
    DeviceWidget(QWidget *parent = 0);
    virtual ~DeviceWidget();

public:
    void init();
    void setCanDevice();
    void updateDeviceType();

protected:
    void updateListDevice();
    void updateTablePoint();

signals:
    void sigModified();

protected slots:
    void addDevice();
    void removeDevice();
    void beginRenameDevice(QListWidgetItem* item);
    void renameDevice(QWidget* editor);
    void deviceSelectionChanged(int selection);
    void setDevType();

    void canDeviceStateChanged(bool);

private:
    QCheckBox* m_cbCanDevice;
    QListWidget* m_lwDevice;
    QPushButton* m_pbDevAdd;
    QPushButton* m_pbDevRemove;
    QComboBox* m_cbDevType;
    QPushButton* m_pbSetType;

    QTableWidget* m_twPoint;

    quint32 m_curDevice;
    quint32 m_maxDevId;
};

class DeviceView : public RightWidget
{
    Q_OBJECT
public:
    DeviceView(const QString& path);
    virtual ~DeviceView();

public:
    virtual bool init();
    virtual bool updateParm();

protected:
    void makePoints();

protected slots:
    void deviceTypeModified();
    void deviceModified();
    void tabChanged(int tab);

private:
    QTabWidget* m_tab;
    DeviceTypeWidget* m_widgetType;
    DeviceWidget* m_widgetDevice;

    bool m_bPointNeedRemake;
};

#endif // DEVICEVIEW_H
